package filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
//   /*代表拦截所有
@WebFilter(filterName = "hello", urlPatterns = {"/*"})
public class HelloFilter implements Filter{

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("HelloFilter.init()");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("HelloFilter.doFilter()");
		// 如果有下一个过滤器就执行下一个过滤器，如果已经没有过滤器，就放行访问要访问的资源
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		System.out.println("HelloFilter.destroy()");
	}

}
